package com.zelma.house.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.zelma.house.dao.AreaDao;
import com.zelma.house.entity.ResourceEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zelma.house.entity.AreaEntity;
import com.zelma.house.service.AreaService;
import com.zelma.common.utils.PageUtils;
import com.zelma.common.utils.R;



/**
 * 
 *
 * @author zelma
 * @email 1239115389@qq.com
 * @date 2022-01-06 16:53:19
 */
@RestController
@RequestMapping("house/area")
public class AreaController {
    private static Logger logger = LoggerFactory.getLogger(AreaController.class);

    @Autowired
    private AreaService areaService;

    @Autowired
    private AreaDao areaDao;

    /*
     *
     * 递归查询省市县
     * */
    @GetMapping("/areaList")
    public R areaList(@RequestParam("id") Integer id){
        List<AreaEntity> areaList=areaService.queryChildren(id);
        return R.ok().put("省市县的数为:",areaList);
    }

    /*
     *
     * 分片查询省市县--wq
     * */
    @XxlJob("cityList")
    @GetMapping("/cityList")
    public List<AreaEntity> cityList(){
        // 分片参数
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        XxlJobHelper.log("分片参数：当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);
        List<AreaEntity> list=areaDao.selecarea(shardIndex,shardTotal);
        list.forEach(c->{
            System.out.println("id"+c.getId()+"-"+"title:"+c.getCname());
        });
        return list;
    }

}
